package com.bstech;

import java.io.File;

import com.bstech.Classi.Common;
import com.bstech.Classi.ApplicationVersion;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;

public class UpdateActivity extends Activity {

	private ApplicationVersion newVersion;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		Bundle bundle = getIntent().getExtras();
		if(bundle != null)
			newVersion = (ApplicationVersion)bundle.getSerializable("update");
		
		if(newVersion != null)
		{
			//aggiorno
			File apk = new File(Common.UpdatesFilePath + newVersion.FileName);
			Intent intent = new Intent(Intent.ACTION_VIEW);
			intent.setDataAndType(Uri.fromFile(apk), "application/vnd.android.package-archive");
			startActivity(intent);  
			finish();
//			
//			 new AlertDialog.Builder(this)
//		        .setIcon(android.R.drawable.ic_dialog_alert)
//		        .setTitle("Aggiornamento")
//		        .setMessage("Procedere all'aggiornamento del software?\nI rapporti non salvati andranno persi.")
//		        .setPositiveButton("Conferma",new OnClickListener() {
//					@Override
//					public void onClick(DialogInterface dialog, int which) {
//						//aggiorno
//						File apk = new File(Common.UpdatesFilePath + newVersion.FileName);
//						Intent intent = new Intent(Intent.ACTION_VIEW);
//						intent.setDataAndType(Uri.fromFile(apk), "application/vnd.android.package-archive");
//						startActivity(intent);  
//						finish();
//					}
//				})
//		        .setNegativeButton("Annulla", new OnClickListener() {
//					@Override
//					public void onClick(DialogInterface dialog, int which) {
//						//non aggiorno
//						finish();
//					}
//				}).setCancelable(false)
//		        .show();
		}
		else
			finish();
	}
}
